package com.logic.modular.game.battle.process.skillEffectHandle.impl;

import com.logic.modular.game.battle.panel.attribute.domain.EffectStatus;
import com.logic.modular.game.battle.panel.attribute.domain.PlayerHeroAttribute;
import com.logic.modular.game.battle.process.skillEffectHandle.base.BaseSkillEffectStrategy;
import com.logic.modular.game.battle.panel.skillEffect.PvpSkillEffect;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

@Slf4j
public class ControlStrategy {
    @Component
    public static class BaseControlStrategy extends BaseSkillEffectStrategy {
        @Override
        public PvpSkillEffect applyEffect(PvpSkillEffect pvpSkillEffect) {
            effectHandle2.tryTriggerJudgment(pvpSkillEffect);
            effectHandle2.logTriggerFailReasons(pvpSkillEffect);
            apply(pvpSkillEffect);
            return pvpSkillEffect;
        }

        @Override
        public PvpSkillEffect apply(PvpSkillEffect pvpSkillEffect) {
            if (pvpSkillEffect.status.getIsTrigger()!=1) {
                return pvpSkillEffect;
            }
            String battleUUID = pvpSkillEffect.getBattleUUID();
            Long battleId = pvpSkillEffect.getBattleId();
            Integer trigger6 = pvpSkillEffect.getBaseTrigger().getTrigger6();
            Long sourcePlayerHeroId = pvpSkillEffect.getSourcePlayerHeroId();
            Long targetPlayerHeroId = pvpSkillEffect.getTargetPlayerHeroId();
            Long coreSkillEffectTypeId = pvpSkillEffect.getCoreSkillEffectTypeId();
            String fieldName = pvpSkillEffect.getSkillEffectLayer().getName();
            double value = pvpSkillEffect.getMagicInfluence() / 100.0;

            PlayerHeroAttribute sourceAttribute = attributeService.get(battleUUID, sourcePlayerHeroId);

            List<PlayerHeroAttribute> targetHeroes =
                    releaseSkillService2.getTargetHeroes(battleUUID, targetPlayerHeroId, trigger6);
            for (PlayerHeroAttribute targetAttribute : targetHeroes) {
                Map<Long, EffectStatus> status = targetAttribute.getStatus();
                EffectStatus effectStatus = status.get(coreSkillEffectTypeId);
                if (effectStatus == null) {
                    effectStatus = EffectStatus.getEffectStatus(pvpSkillEffect, sourceAttribute);
                    status.put(23L, effectStatus);
                    targetAttribute.setStatus(status);
                    attributeService.saveCache(targetAttribute);
                }
            }
            return pvpSkillEffect;
        }


        public void obtainEffectStatus(PvpSkillEffect pvpSkillEffect) {
            String battleUUID = pvpSkillEffect.getBattleUUID();
            Long coreSkillEffectTypeId = pvpSkillEffect.getCoreSkillEffectTypeId();

            Long targetPlayerHeroId = pvpSkillEffect.getTargetPlayerHeroId();
            PlayerHeroAttribute targetAttribute = attributeService.get(battleUUID, targetPlayerHeroId);

            Long sourcePlayerHeroId = pvpSkillEffect.getSourcePlayerHeroId();
            PlayerHeroAttribute sourceAttribute = attributeService.get(battleUUID,sourcePlayerHeroId );

            Map<Long, EffectStatus> status = targetAttribute.getStatus();
            EffectStatus effectStatus = status.get(coreSkillEffectTypeId);
            if (effectStatus == null) {
                effectStatus = EffectStatus.getEffectStatus(pvpSkillEffect, sourceAttribute);
                status.put(23L, effectStatus);
                targetAttribute.setStatus(status);
                attributeService.saveCache(targetAttribute);
            }
        }
    }

    // 23	混乱	无法行动（控制状态）				21
    @Slf4j
    @Component
    public static class Control_23 extends BaseControlStrategy {}

    // 24	缴械	无法普通攻击（控制状态）				21
    @Slf4j
    @Component
    public static class Control_24 extends BaseControlStrategy {}

    // 25	技穷	无法主动战法（控制状态）				21
    @Slf4j
    @Component
    public static class Control_25 extends BaseControlStrategy {}

    // 26	暴走	无法正确攻击目标(改成敌我全体)				21
    @Slf4j
    @Component
    public static class Control_26 extends BaseControlStrategy {}

    // 54	嘲讽	无法正确普通攻击目标(改为嘲讽自己的对象)				21
    @Slf4j
    @Component
    public static class Control_54 extends BaseControlStrategy {}
}
